package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesRecommenderService;
import com.yixun.qfbao.apidto.GetPremisesDetailReqDto;
import com.yixun.qfbao.apidto.PremisesRecommenderDto;
import com.yixun.qfbao.apidto.PremisesRecommenderListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetPremisesDetailReqVo;
import com.yixun.qfbao.xf.model.PremisesRecommender;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: channel-parent
 *
 * @description: 楼盘推荐人列表
 *
 * @author: Seven.wang
 *
 * @create: 2019-11-05 16:20
 **/
@Service("premisesRecommenderListHander")
public class PremisesRecommenderListHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(PremisesRecommenderListHander.class);

    @Autowired
    PremisesRecommenderService premisesRecommenderService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GetPremisesDetailReqVo req = (GetPremisesDetailReqVo)reqDto;
        GetPremisesDetailReqDto reqDto1 = req.getParams();
        BaseResponseDTO<PremisesRecommenderListResDto> res = new BaseResponseDTO<>();
        PremisesRecommenderListResDto resDto = new PremisesRecommenderListResDto();
        try {
            if(reqDto1.getId() == null){
                res.setResult(ResultEnum.FAIL.getNo());
                res.setErrorMsg("楼盘不能为空!");
                return res;
            }
            List<PremisesRecommenderDto> dtoList = premisesRecommenderService.selectListByPremisesId(reqDto1.getId());
            resDto.setList(dtoList);
            resDto.setResult(ResultEnum.SUCCESS.getNo());
            res.setResData(resDto);
            res.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            logger.error("PremisesRecommenderListHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("推荐人查询失败!");
        }
        return res;
    }
}
